﻿using UnityEngine;
using System.Collections;

namespace UI
{
    public class RushFightReadyItem : MonoBehaviour
    {
        public UILabel recommandFightScoreLabel;
        public UILabel rewardPointLabel;
        public UILabel rewardCoinLabel;

        int star;
        string taskId;

        RushFightReadyPage curPage;

        public void Init(ProtoBuf.Message.RushTaskInfo info, RushFightReadyPage page) {
            recommandFightScoreLabel.text = info.fightScore.ToString();
            rewardPointLabel.text = info.point.ToString();
            rewardCoinLabel.text = info.coin.ToString();
            star = info.star;
            taskId = info.taskId;
            Show();
            this.curPage = page;
        }

        public void Show() {
            gameObject.SetActive(true);
        }

        public void Hide() {
            gameObject.SetActive(false);
        }

        public void OnFightBtnClick() {
            var rr = Room.RoomManager.currentRoom as Room.RoomRush;
            if (rr != null) {
                rr.MainActorRush();
                rr.isReadyForBattle = false;
            }
            ProtoBuf.Message.CSRushFightStart msg = new ProtoBuf.Message.CSRushFightStart();
            msg.rushType = 1;
            msg.star = star;
            msg.taskId = taskId;
            NetAPI.SendHttp(ProtoBuf.Message.OpDefine.CSRushFightStart, msg, (pack, b) =>
            {
                if (b)
                {
                    ProtoBuf.Message.SCRushFightStart _msg = pack.kBody as ProtoBuf.Message.SCRushFightStart;
                    StaticData.curBattleData.SetData(_msg, true);
                    if (rr != null)
                    {
                        rr.isReadyForBattle = true;
                    }
                    curPage.Close();
                }
            });
        }
    }
}
